package com.example.upload.config;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

@Configuration
@EnableConfigurationProperties(FileUploadProperties.class)
public class MvcConfig {


    private final FileUploadProperties fileUploadProperties;

    public MvcConfig(FileUploadProperties fileUploadProperties) {
        this.fileUploadProperties = fileUploadProperties;
    }

    public CommonsMultipartResolver multipartResolver(){
        CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
        multipartResolver.setDefaultEncoding(fileUploadProperties.getDefaultEncoding());
        multipartResolver.setMaxInMemorySize(fileUploadProperties.getMaxInMemorySize());
        multipartResolver.setMaxUploadSize(fileUploadProperties.getMaxUploadSize());
        return multipartResolver;
    }
}
